(name_or_version.to_string(), Some(version))
}
None => {
- if name_or_version.char_at(0).is_alphabetic() {
+ if name_or_version.chars().next().unwrap()
+ .is_alphabetic() {
(name_or_version.to_string(), None)
} else {
let version = try!(name_or_version.to_semver()
#![deny(unused)]
-#![feature(collections, hash, os, std_misc, unicode, core)]
-#![feature(io, path, str_words, fs, old_io, exit_status)]
+#![feature(hash, os, std_misc, unicode, core)]
+#![feature(io, path, str_words, old_io, exit_status, fs_time)]
#![cfg_attr(test, deny(warnings))]
#[cfg(test)] extern crate hamcrest;
}
fn rm_rf(path: &Path) -> CargoResult<()> {
- if path.is_dir() {
+ let m = fs::metadata(path);
+ if m.as_ref().map(|s| s.is_dir()) == Ok(true) {
try!(fs::remove_dir_all(path).chain_error(|| {
human("could not remove build directory")
}));
- } else if path.exists() {
+ } else if m.is_ok() {
try!(fs::remove_file(path).chain_error(|| {
human("failed to remove build artifact")
}));
use std::collections::HashSet;
-use std::io::prelude::*;
+use std::fs;
use std::path::Path;
use std::process::Command;
let path = package.absolute_target_dir().join("doc").join(&name)
.join("index.html");
- if path.exists() {
+ if fs::metadata(&path).is_ok() {
open_docs(&path);
}
}
pub fn new(opts: NewOptions, config: &Config) -> CargoResult<()> {
let path = config.cwd().join(opts.path);
- if path.exists() {
+ if fs::metadata(&path).is_ok() {
return Err(human(format!("Destination `{}` already exists",
path.display())))
}
let filename = format!("package/{}-{}.crate", pkg.name(), pkg.version());
let dst = pkg.absolute_target_dir().join(&filename);
- if dst.exists() { return Ok(Some(dst)) }
+ if fs::metadata(&dst).is_ok() { return Ok(Some(dst)) }
let mut bomb = Bomb { path: Some(dst.clone()) };
fn tar(pkg: &Package, src: &PathSource, config: &Config,
dst: &Path) -> CargoResult<()> {
- if dst.exists() {
+ if fs::metadata(&dst).is_ok() {
return Err(human(format!("destination already exists: {}",
dst.display())))
}
let f = try!(GzDecoder::new(try!(File::open(tar))));
let dst = pkg.root().join(&format!("target/package/{}-{}",
pkg.name(), pkg.version()));
- if dst.exists() {
+ if fs::metadata(&dst).is_ok() {
try!(fs::remove_dir_all(&dst));
}
let mut archive = Archive::new(f);
// Don't recurse into git databases
if dir.file_name().and_then(|s| s.to_str()) == Some(".git") {
- return Ok(false);
+ return Ok(false)
}
// Don't automatically discover packages across git submodules
- if dir != path && dir.join(".git").exists() { return Ok(false); }
+ if dir != path && fs::metadata(&dir.join(".git")).is_ok() {
+ return Ok(false)
+ }
// Don't ever look at target directories
if dir.file_name().and_then(|s| s.to_str()) == Some("target") &&
fn walk<F>(path: &Path, callback: &mut F) -> CargoResult<()>
where F: FnMut(&Path) -> CargoResult<bool>
{
- if !path.is_dir() { return Ok(()) }
+ if fs::metadata(&path).map(|m| m.is_dir()) != Ok(true) {
+ return Ok(())
+ }
if !try!(callback(path)) {
trace!("not processing {}", path.display());
- return Ok(());
+ return Ok(())
}
// Ignore any permission denied errors because temporary directories
//
// If we have an old build directory, then just move it into place,
// otherwise create it!
- if !build_output.exists() {
+ if fs::metadata(&build_output).is_err() {
try!(fs::create_dir(&build_output).chain_error(|| {
internal("failed to create script output directory for \
build command")
if !target.profile().is_doc() {
for filename in try!(cx.target_filenames(target)).iter() {
let dst = root.join(filename);
- missing_outputs |= !dst.exists();
+ missing_outputs |= fs::metadata(&dst).is_err();
if target.profile().is_test() {
cx.compilation.tests.push((target.name().to_string(), dst));
let new2 = new1.clone();
let work1 = Work::new(move |_| {
- if !new1.exists() {
+ if fs::metadata(&new1).is_err() {
try!(fs::create_dir(&new1));
}
Ok(())
});
let work2 = Work::new(move |_| {
- if !new2.exists() {
+ if fs::metadata(&new2).is_err() {
try!(fs::create_dir(&new2));
}
Ok(())
//! ```
use std::fs;
-use std::io::prelude::*;
use std::io;
use std::path::{PathBuf, Path};
}
pub fn prepare(&mut self) -> io::Result<()> {
- if !self.root.exists() {
+ if fs::metadata(&self.root).is_err() {
try!(fs::create_dir_all(&self.root));
}
return Ok(());
fn mkdir(dir: &Path) -> io::Result<()> {
- if !dir.exists() {
+ if fs::metadata(&dir).is_err() {
try!(fs::create_dir(dir));
}
Ok(())
use std::collections::{HashSet, HashMap};
use std::dynamic_lib::DynamicLibrary;
use std::env;
-use std::ffi::{OsStr, AsOsStr, OsString};
+use std::ffi::OsString;
use std::fs;
use std::io::prelude::*;
use std::path::{self, PathBuf};
// this manually
for filename in filenames.iter() {
let dst = root.join(filename);
- if dst.exists() {
+ if fs::metadata(&dst).is_ok() {
try!(fs::remove_file(&dst));
}
}
let layout = cx.layout(package, kind);
cmd.arg("-L").arg(&{
let mut root = OsString::from_str("dependency=");
- root.push_os_str(layout.root().as_os_str());
+ root.push(layout.root());
root
});
cmd.arg("-L").arg(&{
let mut deps = OsString::from_str("dependency=");
- deps.push_os_str(layout.deps().as_os_str());
+ deps.push(layout.deps());
deps
});
for filename in try!(cx.target_filenames(target)).iter() {
if filename.ends_with(".a") { continue }
let mut v = OsString::new();
- v.push_os_str(OsStr::from_str(target.name()));
- v.push_os_str(OsStr::from_str("="));
- v.push_os_str(layout.root().as_os_str());
- let s = path::MAIN_SEPARATOR.to_string();
- v.push_os_str(OsStr::from_str(&s));
- v.push_os_str(OsStr::from_str(&filename));
+ v.push(target.name());
+ v.push("=");
+ v.push(layout.root());
+ v.push(&path::MAIN_SEPARATOR.to_string());
+ v.push(&filename);
cmd.arg("--extern").arg(&v);
}
Ok(())
-use std::ffi::{OsStr, OsString, AsOsStr};
+use std::ffi::OsString;
use std::path::Path;
use core::Source;
for (pkg, libs) in compile.libraries.iter() {
for lib in libs.iter() {
let mut arg = OsString::from_str(pkg.name());
- arg.push_os_str(OsStr::from_str("="));
- arg.push_os_str(lib.as_os_str());
+ arg.push("=");
+ arg.push(lib);
p.arg("--extern").arg(&arg);
}
}
use std::collections::HashMap;
use std::env;
-use std::fs::File;
+use std::fs::{self, File};
use std::io::prelude::*;
use std::iter::repeat;
use std::path::{Path, PathBuf};
};
match *license_file {
Some(ref file) => {
- if !pkg.root().join(file).exists() {
+ if fs::metadata(&pkg.root().join(file)).is_err() {
return Err(human(format!("the license file `{}` does not exist",
file)))
}
fn clone_into(&self, dst: &Path) -> CargoResult<git2::Repository> {
let url = self.url.to_string();
- if dst.exists() {
+ if fs::metadata(&dst).is_ok() {
try!(fs::remove_dir_all(dst));
}
try!(fs::create_dir_all(dst));
human(format!("Couldn't mkdir {}", dirname.display()))
}));
- if into.exists() {
+ if fs::metadata(&into).is_ok() {
try!(fs::remove_dir_all(into).chain_error(|| {
human(format!("Couldn't rmdir {}", into.display()))
}));
// TODO: the `entry` has a mode we should be able to look at instead
// of just calling stat() again
- if file_path.is_dir() {
+ if fs::metadata(&file_path).map(|m| m.is_dir()) == Ok(true) {
warn!(" found submodule {}", file_path.display());
let rel = file_path.relative_from(&root).unwrap();
let rel = try!(rel.to_str().chain_error(|| {
is_root: bool, filter: &mut F) -> CargoResult<()>
where F: FnMut(&Path) -> bool
{
- if !path.is_dir() {
+ if fs::metadata(&path).map(|m| m.is_dir()) != Ok(true) {
if (*filter)(path) {
ret.push(path.to_path_buf());
}
return Ok(())
}
// Don't recurse into any sub-packages that we have
- if !is_root && path.join("Cargo.toml").exists() { return Ok(()) }
+ if !is_root && fs::metadata(&path.join("Cargo.toml")).is_ok() {
+ return Ok(())
+ }
for dir in try!(fs::read_dir(path)) {
let dir = try!(dir).path();
match (is_root, dir.file_name().and_then(|s| s.to_str())) {
// condition where this path was rm'ed - either way,
// we can ignore the error and treat the path's mtime
// as 0.
- let mtime = file.metadata().map(|s| s.modified()).unwrap_or(0);
+ let mtime = fs::metadata(&file).map(|s| s.modified()).unwrap_or(0);
warn!("{} {}", mtime, file.display());
max = cmp::max(max, mtime);
}
// TODO: should discover from the S3 redirect
let filename = format!("{}-{}.crate", pkg.name(), pkg.version());
let dst = self.cache_path.join(&filename);
- if dst.exists() { return Ok(dst) }
+ if fs::metadata(&dst).is_ok() { return Ok(dst) }
try!(self.config.shell().status("Downloading", pkg));
try!(fs::create_dir_all(dst.parent().unwrap()));
-> CargoResult<PathBuf> {
let dst = self.src_path.join(&format!("{}-{}", pkg.name(),
pkg.version()));
- if dst.join(".cargo-ok").exists() { return Ok(dst) }
+ if fs::metadata(&dst.join(".cargo-ok")).is_ok() { return Ok(dst) }
try!(fs::create_dir_all(dst.parent().unwrap()));
let f = try!(File::open(&tarball));
loop {
let possible = current.join(".cargo").join("config");
- if possible.exists() {
+ if fs::metadata(&possible).is_ok() {
let file = try!(File::open(&possible));
try!(walk(file, &possible));
}));
if !pwd.starts_with(&home) {
let config = home.join("config");
- if config.exists() {
+ if fs::metadata(&config).is_ok() {
let file = try!(File::open(&config));
try!(walk(file, &config));
}
use std::env;
-use std::io::prelude::*;
+use std::fs;
use std::path::{Path, PathBuf};
use util::{CargoResult, human, ChainError};
loop {
let manifest = current.join(file);
- if manifest.exists() {
+ if fs::metadata(&manifest).is_ok() {
return Ok(manifest)
}
pub fn find_project_manifest_exact(pwd: &Path, file: &str) -> CargoResult<PathBuf> {
let manifest = pwd.join(file);
- if manifest.exists() {
+ if fs::metadata(&manifest).is_ok() {
Ok(manifest)
} else {
Err(human(format!("Could not find `{}` in `{}`",
}
fn try_add_file(files: &mut Vec<PathBuf>, file: PathBuf) {
- if file.exists() {
+ if fs::metadata(&file).is_ok() {
files.push(file);
}
}
let mut benches = vec!();
let lib_canidate = root_path.join("src").join("lib.rs");
- if lib_canidate.exists() {
+ if fs::metadata(&lib_canidate).is_ok() {
lib = Some(lib_canidate);
}
-#![feature(core, io, path, fs)]
+#![feature(io, path)]
extern crate curl;
extern crate "rustc-serialize" as rustc_serialize;
(json.len() >> 8) as u8,
(json.len() >> 16) as u8,
(json.len() >> 24) as u8,
- ].iter().cloned());
- w.extend(json.as_bytes().iter().cloned());
+ ].iter().map(|x| *x));
+ w.extend(json.as_bytes().iter().map(|x| *x));
w.extend([
(stat.len() >> 0) as u8,
(stat.len() >> 8) as u8,
(stat.len() >> 16) as u8,
(stat.len() >> 24) as u8,
- ].iter().cloned());
+ ].iter().map(|x| *x));
w
};
let tarball = try!(File::open(tarball).map_err(Error::Io));
let url = format!("{}/api/v1/crates/new", self.host);
- let token = try!(self.token.as_ref().ok_or(Error::TokenMissing));
+ let token = match self.token.as_ref() {
+ Some(s) => s,
+ None => return Err(Error::TokenMissing),
+ };
let request = self.handle.put(url, &mut body)
.content_length(size)
.header("Accept", "application/json")
.content_type("application/json");
if authorized == Auth::Authorized {
- let token = try!(self.token.as_ref().ok_or(Error::TokenMissing));
+ let token = match self.token.as_ref() {
+ Some(s) => s,
+ None => return Err(Error::TokenMissing),
+ };
req = req.header("Authorization", &token);
}
match body {